package com.linkstec.musiccloud.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.linkstec.musiccloud.mapper.UserMapper;
import com.linkstec.musiccloud.pojo.User;
import com.linkstec.musiccloud.service.UserService;
import com.linkstec.musiccloud.util.SingerState;

/**
 * @ClassName:UserServiceImpl
 * @Description:TODO UserService的实现类
 * @author liujinhui 
 * @date:2018年11月23日上午10:11:21
 */
@Service
public class UserServiceImpl implements UserService{
	
	@Autowired
	private UserMapper userMapper;
	
	@Override
	public User login(User user) {
		return userMapper.login(user);
	}

	@Override

	public void mUserAdd(User user) throws RuntimeException {
		user.setState(1);
		userMapper.mUserAdd(user);
		
	}


	public void register(User user) {
		user.setSinger(0);
		user.setState(1);
		user.setVip(0);
		userMapper.register(user);
	}
		
		
		@Override
		public List<User> selectAllUser() throws RuntimeException {	
			User user = new User();
			user.setState(1);
			return userMapper.selectAllUser(user);
		}


		@Override
		public User selectUserById(User user) throws RuntimeException {
			return userMapper.selectUserById(user);
		}

		@Override
		public void mUserUpdate(User user) throws RuntimeException {
			userMapper.mUserUpdate(user);
			
		}

		@Override
		public List<User> selectUsers(User user) throws RuntimeException {
			user.setState(1);
			return userMapper.selectUsers(user);
		}

		@Override
		public void deleteUsers(User user) throws RuntimeException {
			user.setState(0);
			for (int i = 0; i < user.getIds().length; i++) {
				user.setUserId(user.getIds()[i]);
				userMapper.deleteUser(user);
			}
			//userMapper.deleteUser(user);
		}
		
		@Override
		public List<User> selectSingers() throws RuntimeException {
			int singer = 2;
			return userMapper.selectSingers(singer);
		}

		@Override
		public void becomeSinger(User user) throws RuntimeException {
			user.setSinger(SingerState.state_singer);
			userMapper.becomeSinger(user.getIds());
			
			
		}

		@Override
		public List<User> selectSinger(String realName) {
			return userMapper.selectSinger(realName);
		}

		@Override
		@Transactional
		public void updateRealName(User user) {
			userMapper.updateRealName(user);
		}


		public void update(User user) {
			userMapper.update(user);
		}

		@Override
		public User selectPath(int userId) {
			return userMapper.selectPath(userId);
		}

}
